﻿#region

using System.Collections.Generic;

using Microsoft.Xna.Framework;

#endregion

namespace Pob.GameObjects
{
    public class MenuItemGroup
    {
        #region Fields

        private readonly Color _color;

        private readonly DrawStringMode _drawStringMode;

        private readonly string _font;

        private readonly Game _game;

        private readonly List<MenuItem> _menuItems = new List<MenuItem>();

        private readonly OringeMode _oringeMode;

        private readonly Settings _settings;

        #endregion

        #region Constructors and Destructors

        public MenuItemGroup(Game game, string font, Color color, OringeMode oringeMode = OringeMode.MiddleCenter, DrawStringMode drawStringMode = DrawStringMode.Minimal)
        {
            _settings = SettingsManager.CurrentInstance.Settings;

            _game = game;
            _font = font;
            _color = color;
            _oringeMode = oringeMode;
            _drawStringMode = drawStringMode;
        }

        #endregion

        #region Public Properties

        public List<MenuItem> MenuItems
        {
            get
            {
                return _menuItems;
            }
        }

        #endregion

        #region Public Methods and Operators

        public void Add(string text, MenuItemEvent menuItemEvent, bool selected = false)
        {
            _menuItems.Add(new MenuItem(_game, new DrawString(_game, _font, text, new Vector2(0, 0), _color, selected: selected, originMode: _oringeMode, drawStringMode: _drawStringMode), menuItemEvent));
        }

        public void AddExtended(string text, MenuItemExtendedMode extendedMode, MenuItemEvent menuItemEvent, string value, bool selected = false)
        {
            _menuItems.Add(new MenuItem(_game, new DrawString(_game, _font, text, new Vector2(0, 0), _color, selected: selected, originMode: _oringeMode, drawStringMode: _drawStringMode), menuItemEvent, extendedMode, value));
        }

        public void CalculatePositions()
        {
            var height = (_settings.Height - (_menuItems.Count * 50)) / 2;

            foreach (var menuItem in _menuItems)
            {
                if (menuItem.Extended)
                {
                    menuItem.Item.Position = new Vector2((_settings.Width / 2f) - 300, height);
                    menuItem.ItemExtension.Position = new Vector2((_settings.Width / 2f) + 100, height);
                    height += 50;
                }
                else
                {
                    menuItem.Item.Position = new Vector2(_settings.Width / 2f, height);
                    height += 50;
                }
            }
        }

        #endregion
    }
}